package com.neusoft.demo.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.neusoft.demo.dao.GoodsMapper;
import com.neusoft.demo.po.Goods;
import com.neusoft.demo.utils.SqlSessionFactoryUtil;

@WebServlet("/LieBiaoServlet")
public class LieBiaoServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
		
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//接收传来的商品类型
		Integer type_id = Integer.valueOf(request.getParameter("type_id"));
		// 创建SqlSession对象
		SqlSession session = SqlSessionFactoryUtil.getSqlSessionFactory().openSession();;
		//生成代理类
		GoodsMapper goodsMapper	= session.getMapper(GoodsMapper.class);		
		//获得商品的list集合
		List<Goods> list = goodsMapper.findGoods(type_id);
		request.setAttribute("list", list);
		// 在跳转页面
		request.getRequestDispatcher("liebiao.jsp").forward(request, response);	
		// 释放资源
		session.close();
	}

}
